﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 热水器
{
    /// <summary>
    /// 热水器
    /// </summary>
    class Heater
    {
        public delegate void TemperatureDelegate(int temp);
        public event TemperatureDelegate temperatureEvent;  //水温事件
        public event TemperatureDelegate alarmEvent;    //警报器事件

        private int _temperature;    //温度

        //烧水
        public void BoilWater()
        {
            for (int i = 0; i <= 100; i++)
            {
                _temperature = i;
                //向外部报水温
                if (temperatureEvent!=null)
                {
                    temperatureEvent(_temperature);
                }
                //如果水温大于98度
                if (_temperature>=98)
                {
                    alarmEvent?.Invoke(_temperature);
                }
            }
        }
    }
}
